home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / ASM-MIPS / STRING.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  3KB  |  149 lines

  1. /* $Id: string.h,v 1.6 1998/07/20 17:52:21 ralf Exp $
  2.  *
  3.  * This file is subject to the terms and conditions of the GNU General Public
  4.  * License.  See the file "COPYING" in the main directory of this archive
  5.  * for more details.
  6.  *
  7.  * Copyright (c) 1994, 1995, 1996, 1997, 1998 by Ralf Baechle
  8.  */
  9. #ifndef __ASM_MIPS_STRING_H
  10. #define __ASM_MIPS_STRING_H
  11.  
  12. #define __HAVE_ARCH_STRCPY
  13. extern __inline__ char *strcpy(char *__dest, __const__ char *__src)
  14. {
  15.   char *__xdest = __dest;
  16.  
  17.   __asm__ __volatile__(
  18.     ".set\tnoreorder\n\t"
  19.     ".set\tnoat\n"
  20.     "1:\tlbu\t$1,(%1)\n\t"
  21.     "addiu\t%1,1\n\t"
  22.     "sb\t$1,(%0)\n\t"
  23.     "bnez\t$1,1b\n\t"
  24.     "addiu\t%0,1\n\t"
  25.     ".set\tat\n\t"
  26.     ".set\treorder"
  27.     : "=r" (__dest), "=r" (__src)
  28.         : "0" (__dest), "1" (__src)
  29.     : "$1","memory");
  30.  
  31.   return __xdest;
  32. }
  33.  
  34. #define __HAVE_ARCH_STRNCPY
  35. extern __inline__ char *strncpy(char *__dest, __const__ char *__src, size_t __n)
  36. {
  37.   char *__xdest = __dest;
  38.  
  39.   if (__n == 0)
  40.     return __xdest;
  41.  
  42.   __asm__ __volatile__(
  43.     ".set\tnoreorder\n\t"
  44.     ".set\tnoat\n"
  45.     "1:\tlbu\t$1,(%1)\n\t"
  46.     "subu\t%2,1\n\t"
  47.     "sb\t$1,(%0)\n\t"
  48.     "beqz\t$1,2f\n\t"
  49.     "addiu\t%0,1\n\t"
  50.     "bnez\t%2,1b\n\t"
  51.     "addiu\t%1,1\n"
  52.     "2:\n\t"
  53.     ".set\tat\n\t"
  54.     ".set\treorder"
  55.         : "=r" (__dest), "=r" (__src), "=r" (__n)
  56.         : "0" (__dest), "1" (__src), "2" (__n)
  57.         : "$1","memory");
  58.  
  59.   return __dest;
  60. }
  61.  
  62. #define __HAVE_ARCH_STRCMP
  63. extern __inline__ int strcmp(__const__ char *__cs, __const__ char *__ct)
  64. {
  65.   int __res;
  66.  
  67.   __asm__ __volatile__(
  68.     ".set\tnoreorder\n\t"
  69.     ".set\tnoat\n\t"
  70.     "lbu\t%2,(%0)\n"
  71.     "1:\tlbu\t$1,(%1)\n\t"
  72.     "addiu\t%0,1\n\t"
  73.     "bne\t$1,%2,2f\n\t"
  74.     "addiu\t%1,1\n\t"
  75.     "bnez\t%2,1b\n\t"
  76.     "lbu\t%2,(%0)\n\t"
  77. #if _MIPS_ISA == _MIPS_ISA_MIPS1
  78.     "nop\n\t"
  79. #endif
  80.     "move\t%2,$1\n"
  81.     "2:\tsubu\t%2,$1\n"
  82.     "3:\t.set\tat\n\t"
  83.     ".set\treorder"
  84.     : "=r" (__cs), "=r" (__ct), "=r" (__res)
  85.     : "0" (__cs), "1" (__ct)
  86.     : "$1");
  87.  
  88.   return __res;
  89. }
  90.  
  91. #define __HAVE_ARCH_STRNCMP
  92. extern __inline__ int strncmp(__const__ char *__cs, __const__ char *__ct, size_t __count)
  93. {
  94.   int __res;
  95.  
  96.   __asm__ __volatile__(
  97.     ".set\tnoreorder\n\t"
  98.     ".set\tnoat\n"
  99.     "1:\tlbu\t%3,(%0)\n\t"
  100.     "beqz\t%2,2f\n\t"
  101.     "lbu\t$1,(%1)\n\t"
  102.     "subu\t%2,1\n\t"
  103.     "bne\t$1,%3,3f\n\t"
  104.     "addiu\t%0,1\n\t"
  105.     "bnez\t%3,1b\n\t"
  106.     "addiu\t%1,1\n"
  107.     "2:\tmove\t%3,$1\n"
  108.     "3:\tsubu\t%3,$1\n\t"
  109.     ".set\tat\n\t"
  110.     ".set\treorder"
  111.     : "=r" (__cs), "=r" (__ct), "=r" (__count), "=r" (__res)
  112.     : "0" (__cs), "1" (__ct), "2" (__count)
  113.     : "$1");
  114.  
  115.   return __res;
  116. }
  117.  
  118. #define __HAVE_ARCH_MEMSET
  119. extern void *memset(void *__s, int __c, size_t __count);
  120.  
  121. #define __HAVE_ARCH_MEMCPY
  122. extern void *memcpy(void *__to, __const__ void *__from, size_t __n);
  123.  
  124. #define __HAVE_ARCH_MEMMOVE
  125. extern void *memmove(void *__dest, __const__ void *__src, size_t __n);
  126.  
  127. /* Don't build bcopy at all ...  */
  128. #define __HAVE_ARCH_BCOPY
  129.  
  130. #define __HAVE_ARCH_MEMSCAN
  131. extern __inline__ void *memscan(void *__addr, int __c, size_t __size)
  132. {
  133.     char *__end = (char *)__addr + __size;
  134.  
  135.     __asm__(".set\tnoat\n"
  136.         "1:\tbeq\t%0,%1,2f\n\t"
  137.         "addiu\t%0,1\n\t"
  138.         "lb\t$1,-1(%0)\n\t"
  139.         "bne\t$1,%4,1b\n"
  140.         "2:\t.set\tat"
  141.         : "=r" (__addr), "=r" (__end)
  142.         : "0" (__addr), "1" (__end), "r" (__c)
  143.         : "$1");
  144.  
  145.     return __addr;
  146. }
  147.  
  148. #endif /* __ASM_MIPS_STRING_H */
  149.